using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Configuration;
using System.Web.UI;
using System.Web.UI.WebControls;


public partial class JobSeekers_BlockSearchs : System.Web.UI.Page
{
    string connectionString = "";
    protected void Page_Load(object sender, EventArgs e)
    {
        connectionString =
                     WebConfigurationManager.ConnectionStrings[
                       "RecruitVietnam"].ConnectionString;
        if (Session.Contents["jsuserid"] == null)
        {
            Response.Redirect("login.aspx");
        }
        if (!IsPostBack)
            ShowData();

    }
    protected void btnNew_Click(object sender, EventArgs e)
    {
        Response.Redirect("blocksearch.aspx");
    }
    protected void btnDelete_Click(object sender, EventArgs e)
    {
        string lockID = "";
        foreach (GridViewRow gridViewRow in GridView1.Rows)
        {
            CheckBox checkBox = (CheckBox)
            gridViewRow.FindControl("chkBlockSearchID");
            if (checkBox.Checked)
            {
                try
                {
                    lockID +=
                    gridViewRow.Cells[1].Text + ",";
                }
                catch (Exception ex)
                {
                    literalError.Text = ex.Message;
                }
            }

        }
        if (lockID != "")
        {
            lockID = lockID.Substring(0, lockID.Length - 1);
            RecruitVietnam recruitVietnam
                        = new RecruitVietnam();
            recruitVietnam.ConnectionString = 
            connectionString;
            foreach (string id in lockID.Split(','))
                recruitVietnam.DeleteBlockSearch(
                Convert.ToString(Session["jsuserid"]), id);
            ShowData();
        }
    }
     
    void ShowData()
    {
        try
        {
            SqlServerProvider cls = new 
            SqlServerProvider(connectionString);
            cls.CommandText = "SPViewBlockSearch";
            cls.ParameterCollection = new 
            string[1] { "@UserID" };
            cls.ValueCollection = new string[1] { 
            Convert.ToString(Session.Contents["jsuserid"]) };
            cls.CommandType = CommandType.StoredProcedure;
            DataTable dataTable = cls.GetDataTable();
            GridViewHelper helper = 
            new GridViewHelper();
            helper.FillDataTableToGridView(
            dataTable, this.GridView1);

              
            if (GridView1.Rows.Count > 0)
            {
                btnDelete.Enabled = true;
            }
            else
            {
                btnDelete.Enabled = false;
            }

            if (dataTable.Rows.Count >= 10)
                btnNew.Enabled = false;
            else
                btnNew.Enabled = true;
        }
        catch (Exception ex)
        {
            literalError.Text = ex.Message;
        }
    }
     
     
     
}
